package service

import (
	"context"
	"driver_srv/basic/driverproto"
	"driver_srv/handler/dao"
	"driver_srv/handler/models"
	"errors"
)

// DriverCreate 实现添加司机接口
func (s *Server) DriverCreate(_ context.Context, in *__.DriverCreateReq) (*__.DriverCreateResp, error) {
	var driver models.Driver
	createDriver, err := dao.CreateDriver(in, &driver)
	if err != nil {
		return nil, err
	}
	return createDriver, nil

}

// DriverCreate 实现修改司机接口
func (s *Server) DriverUpdate(_ context.Context, in *__.DriverUpdateReq) (*__.DriverUpdateResp, error) {
	var driver models.Driver
	err := dao.UpdateDriver(in, &driver)
	if err != nil {
		return nil, errors.New("修改司机信息失败")
	}
	return &__.DriverUpdateResp{
		Id:                  int64(driver.Id),
		DriverLicenseNumber: driver.DriverLicenseNumber,
	}, nil

}

// DriverCreate 创建司机证件图片
func (s *Server) DriverIdImgCreate(_ context.Context, in *__.DriverIdImgCreateReq) (*__.DriverIdImgCreateResp, error) {
	create, err := dao.DriverIdImgCreate(in)
	if err != nil {
		return nil, errors.New("创建司机证件图片失败")
	}
	return create, nil
}

// DriverCreate 驾驶员培训课程创建
func (s *Server) DriverTrainingCourseCreate(_ context.Context, in *__.DriverTrainingCourseCreateReq) (*__.DriverTrainingCourseCreateResp, error) {
	create, err := dao.DriverTrainingCourseCreate(in)
	if err != nil {
		return nil, errors.New("驾驶员培训课程创建失败")
	}
	return create, nil
}

// DriverCreate 银行账户创建
func (s *Server) BankAccountCreate(_ context.Context, in *__.BankAccountCreateReq) (*__.BankAccountCreateResp, error) {
	create, err := dao.BankAccountCreate(in)
	if err != nil {
		return nil, errors.New("银行账户创建失败")
	}
	return create, nil
}

// 司机与车辆绑定/解绑
func (s *Server) VehicleBind(_ context.Context, in *__.VehicleBindReq) (*__.VehicleBindResp, error) {
	// 调用DAO层执行绑定/解绑操作
	err := dao.VehicleBind(in)
	if err != nil {
		return &__.VehicleBindResp{
			Success: false,
			Message: err.Error(),
		}, nil
	}
	return &__.VehicleBindResp{
		Success: true,
		Message: "操作成功",
	}, nil
}

// DriverList 实现司机详情列表查询接口
func (s *Server) DriverList(_ context.Context, in *__.DriverListReq) (*__.DriverListResp, error) {
	// 调用DAO层执行列表查询
	list, err := dao.DriverList(in)
	if err != nil {
		return nil, errors.New("查询司机列表详情失败：" + err.Error())
	}
	return list, nil
}

// DriverLists 司机列表
func (s *Server) DriverLists(_ context.Context, in *__.DriverListsReq) (*__.DriverListsResp, error) {
	// 调用DAO层执行列表查询
	list, err := dao.DriverLists(in)
	if err != nil {
		return nil, errors.New("查询所有司机列表失败：" + err.Error())
	}
	return list, nil
}

// DriverCarpoolAddressList 司机顺风车地址列表
func (s *Server) DriverCarpoolAddressList(_ context.Context, in *__.DriverCarpoolAddressListReq) (*__.DriverCarpoolAddressListResp, error) {
    list, err := dao.DriverCarpoolAddressList(in)
    if err != nil {
        return nil, errors.New("查询司机顺风车地址失败：" + err.Error())
    }
    return list, nil
}

// 司机营业额查询
func (s *Server) DriverRevenue(_ context.Context, in *__.DriverRevenueReq) (*__.DriverRevenueResp, error) {
	revenue, err := dao.DriverRevenue(in)
	if err != nil {
		return nil, errors.New("获取司机营业额失败：" + err.Error())
	}
	return revenue, nil
}
